/*================================================================
*   Copyright (C) 2020 Sangfor Ltd. All rights reserved.
*   
*   文件名称：test.c
*   创 建 者：Ann
*   创建日期：2020年05月16日
*   描    述：
*
================================================================*/

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>

int main()
{
    int fd[2];
    int ret = pipe(fd);
    if(ret < 0)
    {
        perror("pipe");
        return 0;
    }

    int flagwrite =  fcntl(fd[0], F_GETFL);
    flagwrite |= O_NONBLOCK;
    fcntl(fd[0], F_SETFL, flagwrite);
    
    close(fd[1]);
    
    char buf[1024] = {0};
    int readsize = read(fd[0], buf, sizeof(buf) - 1);
    printf("readsize = %d\n", readsize);
    perror("read");

    return 0;
}
